﻿#region License
//  Distrubted Under the GNU Public License version 2 (GPLv2)
// ========================================
// 
//  QuizzMasterStudio Version 3 
//  Copyright © 2012 , The Sparks (Autism App Jam 2014)
//  All rights reserved.  
// 
// Robert Long, Zephyr Yao, Hillary Chansavang, Li Xiao, Arial Xiao
// 
//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//  
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//  
//  You should have received a copy of the GNU General Public License
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
//  The full license is also included in the root folder.
// 
// Robert Long
//  Email: rbtLong@live.com
#endregion

using System;
using System.Windows.Controls;
using Core.Avatar;
using Core.Features.Background;
using Core.Features.FillIn;
using Core.Features.Journal;
using Core.Features.MainMenu;
using Core.Features.MainMenu.ViewModel;
using Core.Features.Matching;
using Core.Features.Results;
using Core.Util;

namespace Core.ViewModel
{
    internal class MainMenuInitializer
    {
        private readonly MainMenuDialog _menu;
        private readonly ContentPresenter _dlgPresenter;
        private readonly Turtle _turtle;
        private MainMenuDialogVM _menuVm;


        private UserJournal _journal;
        private PhoneNumberGame _phone;
        private BackgroundChanger _bgChanger;
        private MatchingGame _matching;
        private UserResults _results;

        internal MainMenuInitializer(MainMenuDialog menu, 
            ContentPresenter dlgPresenter, Turtle turtle)
        {
            _menu = menu;
            _dlgPresenter = dlgPresenter;
            _turtle = turtle;

            _menu = new MainMenuDialog();
            _menu.ViewModelLoaded += menuOnViewModelLoaded;
            _dlgPresenter.Content = _menu;
            _menu.FadeIn(1100);  
        }

        private void menuOnViewModelLoaded(object sender, EventArgs eventArgs)
        {
            _menuVm = _menu.DataContext as MainMenuDialogVM;
            _menuVm.OnFeatureSelected += (o, args) =>
            {
                if (args.Feature is UserJournal)
                {
                    _journal = args.Feature as UserJournal;
                    new JournalDialogInitializer(_dlgPresenter,
                        _turtle, _menu, _journal);
                }
                else if (args.Feature is PhoneNumberGame)
                {
                    _phone = args.Feature as PhoneNumberGame;
                    new PhoneGameInitializer(_turtle, 
                        _menu, _phone, _dlgPresenter);
                }
                else if (args.Feature is BackgroundChanger)
                {
                    _bgChanger = args.Feature as BackgroundChanger;
                    new BackgroundChangerIntializer(_dlgPresenter,
                        _menu, _turtle, _bgChanger);
                }
                else if (args.Feature is MatchingGame)
                {
                    _matching = args.Feature as MatchingGame;
                    new MatchingGameInitializer(_menu, _dlgPresenter, _matching);
                }
                else if (args.Feature is UserResults)
                {
                    _results = args.Feature as UserResults;
                    new UserResultsInitializer(_menu, _dlgPresenter, _results);
                }
            };
        }

    }
}
